package com.c1202m.gui;

import com.c1202m.dao.DangNhapDAO;
import com.c1202m.util.KiemTraDuLieu;
import com.c1202m.dao.QuyDinhDAO;
import com.c1202m.hibernate.entities.QuyDinh;
import java.awt.Image;
import java.io.File;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.text.JTextComponent;

public class Help extends javax.swing.JDialog {

    public static int soDuToiThieu = 50000;
    public static int guiToiThieu = 100000;
    public static int rutToiThieuGD = 50000;
    public static int rutToiDaGD = 3000000;
    public static int rutToiDaN = 10000000;
    public static int soLanRutToiDaN = 5;
    private File file = null;

    public Help(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        Image icon = getToolkit().getImage(getClass().getResource("/images/userguide.png"));
        setIconImage(icon);
        setLocationRelativeTo(DangNhapDAO.as);
        setVisible(true);

        file = new File("quydinh.txt");
        boolean isExists = file.exists();
        if (isExists) {
            QuyDinh quyDinh = QuyDinhDAO.docFile(file.getName());
            soDuToiThieu = quyDinh.getGuiToiThieu();
            guiToiThieu = quyDinh.getGuiToiThieu();
            rutToiThieuGD = quyDinh.getRutToiThieuGD();
            rutToiDaGD = quyDinh.getRutToiDaGD();
            rutToiDaN = quyDinh.getRutToiDaN();
            soLanRutToiDaN = quyDinh.getSoLanRutToiDaN();
        } else {
            new CustomMessageDialog(null, true, "Warning!", "không tìm thấy file quydinh.txt", CustomMessageDialog.MESSAGE);
            return;
        }

        Locale loc = new Locale("vi","VN");
        NumberFormat nf = NumberFormat.getCurrencyInstance(loc);

        txtSoDuToiThieu.setText(nf.format(soDuToiThieu));
        txtGuiToiThieu.setText(nf.format(guiToiThieu));
        txtRutToiThieuGD.setText(nf.format(rutToiThieuGD));
        txtRutToiDaGD.setText(nf.format(rutToiDaGD));
        txtRutToiDaN.setText(nf.format(rutToiDaN));
        txtSoLanRutToiDaN.setText(String.valueOf(soLanRutToiDaN));
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleButton1 = new javax.swing.JToggleButton();
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jXTitledSeparator1 = new org.jdesktop.swingx.JXTitledSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jXTextArea1 = new org.jdesktop.swingx.JXTextArea();
        jXTitledSeparator2 = new org.jdesktop.swingx.JXTitledSeparator();
        jScrollPane2 = new javax.swing.JScrollPane();
        jXTextArea2 = new org.jdesktop.swingx.JXTextArea();
        jXTitledSeparator3 = new org.jdesktop.swingx.JXTitledSeparator();
        jScrollPane3 = new javax.swing.JScrollPane();
        jXTextArea3 = new org.jdesktop.swingx.JXTextArea();
        jPanel4 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtSoDuToiThieu = new javax.swing.JTextField();
        txtGuiToiThieu = new javax.swing.JTextField();
        txtRutToiThieuGD = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtRutToiDaGD = new javax.swing.JTextField();
        txtRutToiDaN = new javax.swing.JTextField();
        txtSoLanRutToiDaN = new javax.swing.JTextField();
        btnSua = new javax.swing.JButton();
        btnLuu = new javax.swing.JButton();

        jToggleButton1.setText("jToggleButton1");

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Help & Support");
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        jXTitledSeparator1.setForeground(new java.awt.Color(0, 0, 204));
        jXTitledSeparator1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXTitledSeparator1.setTitle("Quản trị");

        jScrollPane1.setBorder(null);

        jXTextArea1.setEditable(false);
        jXTextArea1.setColumns(20);
        jXTextArea1.setForeground(new java.awt.Color(0, 0, 102));
        jXTextArea1.setLineWrap(true);
        jXTextArea1.setRows(6);
        jXTextArea1.setText("* Xem thông tin về quản trị, chọn \"Quản Trị\" trên thanh công cụ.\n\n* Thay đổi mật khẩu, click vào dòng chữ màu xanh \"Đổi mật khẩu? Click ở đây...\".\n\n* Phần quản trị có các chức năng \"Thêm\", \"Sửa\", \"Xóa\" tài khoản quản trị, chức năng tìm kiếm theo email hoặc họ tên, chức năng hiện hoặc không hiện những tài khoản đã đóng.");
        jXTextArea1.setWrapStyleWord(true);
        jXTextArea1.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jScrollPane1.setViewportView(jXTextArea1);

        jXTitledSeparator2.setForeground(new java.awt.Color(0, 0, 204));
        jXTitledSeparator2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXTitledSeparator2.setTitle("Tài khoản");

        jScrollPane2.setBorder(null);

        jXTextArea2.setEditable(false);
        jXTextArea2.setColumns(20);
        jXTextArea2.setForeground(new java.awt.Color(0, 0, 102));
        jXTextArea2.setLineWrap(true);
        jXTextArea2.setRows(9);
        jXTextArea2.setText("* Chọn \"Tài Khoản\" trên thanh công cụ để xem thông tin về tài khoản, mặc định hiện bảng thông tin tài khoản.\n\n* Xem thông tin giao dịch của từng tài khoản, click vào dòng chữ màu xanh \"Tài khoản / Giao dịch\"\n\n* Bảng thông tin tài khoản có các chức năng \"Thêm\", \"Sửa\" tài khoản, chức năng tìm kiếm theo số tài khoản hoặc tên chủ tài khoản, chức năng hiện hoặc không hiện những tài khoản đã bị đóng.\n\n* Bảng thông tin giao dịch có các chức năng \"Rút Tiền\", \"Gửi Tiền\", \"Chuyển Khoản\", chức năng tìm kiếm theo số tài khoản hoặc tên chủ tài khoản.");
        jXTextArea2.setWrapStyleWord(true);
        jXTextArea2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jScrollPane2.setViewportView(jXTextArea2);

        jXTitledSeparator3.setForeground(new java.awt.Color(0, 0, 204));
        jXTitledSeparator3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jXTitledSeparator3.setTitle("Thống kê");

        jScrollPane3.setBorder(null);

        jXTextArea3.setEditable(false);
        jXTextArea3.setColumns(20);
        jXTextArea3.setForeground(new java.awt.Color(0, 0, 102));
        jXTextArea3.setLineWrap(true);
        jXTextArea3.setRows(2);
        jXTextArea3.setText("* Xem chi tiết các giao dịch, chọn \"Thống Kê\" trên thanh công cụ.\n\n* Bảng thông kê có chức năng tìm kiếm theo số tài khoản và tên chủ tài khoản.");
        jXTextArea3.setWrapStyleWord(true);
        jXTextArea3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jScrollPane3.setViewportView(jXTextArea3);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(70, 70, 70)
                .addComponent(jXTitledSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 483, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(75, Short.MAX_VALUE))
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jXTitledSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 482, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(70, 70, 70)
                        .addComponent(jXTitledSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 483, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jXTitledSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXTitledSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jXTitledSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(71, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Hướng dẫn", new javax.swing.ImageIcon(getClass().getResource("/images/Help-icon.png")), jPanel2); // NOI18N

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Quy định giao dịch"));

        jLabel1.setText("Số dư tối thiểu :");
        jLabel1.setPreferredSize(new java.awt.Dimension(120, 20));

        jLabel2.setText("Gửi tối thiểu :");
        jLabel2.setPreferredSize(new java.awt.Dimension(120, 20));

        jLabel3.setText("Rút tối thiểu / giao dịch :");
        jLabel3.setPreferredSize(new java.awt.Dimension(120, 20));

        txtSoDuToiThieu.setEditable(false);
        txtSoDuToiThieu.setBackground(new java.awt.Color(255, 255, 255));
        txtSoDuToiThieu.setBorder(null);
        txtSoDuToiThieu.setPreferredSize(new java.awt.Dimension(100, 20));

        txtGuiToiThieu.setEditable(false);
        txtGuiToiThieu.setBackground(new java.awt.Color(255, 255, 255));
        txtGuiToiThieu.setBorder(null);
        txtGuiToiThieu.setMinimumSize(new java.awt.Dimension(100, 20));
        txtGuiToiThieu.setPreferredSize(new java.awt.Dimension(100, 20));

        txtRutToiThieuGD.setEditable(false);
        txtRutToiThieuGD.setBackground(new java.awt.Color(255, 255, 255));
        txtRutToiThieuGD.setBorder(null);
        txtRutToiThieuGD.setPreferredSize(new java.awt.Dimension(100, 20));

        jLabel4.setText("Rút tối đa / giao dịch :");
        jLabel4.setPreferredSize(new java.awt.Dimension(120, 20));

        jLabel5.setText("Rút tối đa / ngày :");
        jLabel5.setPreferredSize(new java.awt.Dimension(120, 20));

        jLabel6.setText("Số lần rút tối đa / ngày :");
        jLabel6.setPreferredSize(new java.awt.Dimension(120, 20));

        txtRutToiDaGD.setEditable(false);
        txtRutToiDaGD.setBackground(new java.awt.Color(255, 255, 255));
        txtRutToiDaGD.setBorder(null);
        txtRutToiDaGD.setPreferredSize(new java.awt.Dimension(100, 20));

        txtRutToiDaN.setEditable(false);
        txtRutToiDaN.setBackground(new java.awt.Color(255, 255, 255));
        txtRutToiDaN.setBorder(null);
        txtRutToiDaN.setPreferredSize(new java.awt.Dimension(100, 20));

        txtSoLanRutToiDaN.setEditable(false);
        txtSoLanRutToiDaN.setBackground(new java.awt.Color(255, 255, 255));
        txtSoLanRutToiDaN.setBorder(null);
        txtSoLanRutToiDaN.setPreferredSize(new java.awt.Dimension(100, 20));

        btnSua.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N
        btnSua.setText("   Sửa");
        btnSua.setPreferredSize(new java.awt.Dimension(80, 25));
        btnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSuaActionPerformed(evt);
            }
        });

        btnLuu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/save-icon.png"))); // NOI18N
        btnLuu.setText("   Lưu");
        btnLuu.setEnabled(false);
        btnLuu.setPreferredSize(new java.awt.Dimension(80, 25));
        btnLuu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLuuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnLuu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtRutToiThieuGD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)
                                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(txtSoLanRutToiDaN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtGuiToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(txtRutToiDaN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(txtSoDuToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(20, 20, 20)
                                .addComponent(txtRutToiDaGD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(30, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtSoDuToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRutToiDaGD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtGuiToiThieu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRutToiDaN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRutToiThieuGD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtSoLanRutToiDaN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnLuu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(257, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Quy định", new javax.swing.ImageIcon(getClass().getResource("/images/rule-icon.png")), jPanel4); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSuaActionPerformed
        // TODO add your handling code here:
        txtSoDuToiThieu.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtGuiToiThieu.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtRutToiThieuGD.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtRutToiDaGD.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtRutToiDaN.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtSoLanRutToiDaN.setBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(127, 157, 185)));
        txtSoDuToiThieu.setEditable(true);
        txtGuiToiThieu.setEditable(true);
        txtRutToiThieuGD.setEditable(true);
        txtRutToiDaGD.setEditable(true);
        txtRutToiDaN.setEditable(true);
        txtSoLanRutToiDaN.setEditable(true);
        txtSoDuToiThieu.setText(String.valueOf(soDuToiThieu));
        txtGuiToiThieu.setText(String.valueOf(guiToiThieu));
        txtRutToiThieuGD.setText(String.valueOf(rutToiThieuGD));
        txtRutToiDaGD.setText(String.valueOf(rutToiDaGD));
        txtRutToiDaN.setText(String.valueOf(rutToiDaN));
        txtSoLanRutToiDaN.setText(String.valueOf(soLanRutToiDaN));
        btnSua.setEnabled(false);
        btnLuu.setEnabled(true);
    }//GEN-LAST:event_btnSuaActionPerformed

    private void btnLuuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLuuActionPerformed
        // TODO add your handling code here:
        txtSoDuToiThieu.setBorder(null);
        txtGuiToiThieu.setBorder(null);
        txtRutToiThieuGD.setBorder(null);
        txtRutToiDaGD.setBorder(null);
        txtRutToiDaN.setBorder(null);
        txtSoLanRutToiDaN.setBorder(null);
        QuyDinh quyDinh = new QuyDinh();
        JTextComponent[] tcp = {txtSoDuToiThieu, txtGuiToiThieu, txtRutToiThieuGD, txtRutToiDaGD, txtRutToiDaN, txtSoLanRutToiDaN};
        if (!KiemTraDuLieu.kiemTraTruongTrong(tcp)) {
            return;
        }

        if (!KiemTraDuLieu.isEmpty(txtSoDuToiThieu.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtSoDuToiThieu)) {
                return;
            } else {
                quyDinh.setSoDuToiThieu(Integer.valueOf(txtSoDuToiThieu.getText()));
            }
        }

        if (!KiemTraDuLieu.isEmpty(txtGuiToiThieu.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtGuiToiThieu)) {
                return;
            } else {
                quyDinh.setGuiToiThieu(Integer.valueOf(txtGuiToiThieu.getText()));
            }
        }

        if (!KiemTraDuLieu.isEmpty(txtRutToiThieuGD.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtRutToiThieuGD)) {
                return;
            } else {
                quyDinh.setRutToiThieuGD(Integer.valueOf(txtRutToiThieuGD.getText()));
            }
        }

        if (!KiemTraDuLieu.isEmpty(txtRutToiDaGD.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtRutToiDaGD)) {
                return;
            } else {
                quyDinh.setRutToiDaGD(Integer.valueOf(txtRutToiDaGD.getText()));
            }
        }

        if (!KiemTraDuLieu.isEmpty(txtRutToiDaN.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtRutToiDaN)) {
                return;
            } else {
                quyDinh.setRutToiDaN(Integer.valueOf(txtRutToiDaN.getText()));
            }
        }

        if (!KiemTraDuLieu.isEmpty(txtSoLanRutToiDaN.getText())) {
            if (!KiemTraDuLieu.kiemTraSo(txtSoLanRutToiDaN)) {
                return;
            } else {
                quyDinh.setSoLanRutToiDaN(Integer.valueOf(txtSoLanRutToiDaN.getText()));
            }
        }

        file = new File("quydinh.txt");
        boolean isExists = file.exists();
        if (isExists) {
            QuyDinhDAO.ghiFile(quyDinh, file.getName());
        } else {
            QuyDinhDAO.ghiFile(quyDinh, "quydinh.txt");
        }

        soDuToiThieu = quyDinh.getGuiToiThieu();
        guiToiThieu = quyDinh.getGuiToiThieu();
        rutToiThieuGD = quyDinh.getRutToiThieuGD();
        rutToiDaGD = quyDinh.getRutToiDaGD();
        rutToiDaN = quyDinh.getRutToiDaN();
        soLanRutToiDaN = quyDinh.getSoLanRutToiDaN();

        Locale[] locs = NumberFormat.getAvailableLocales();
        NumberFormat nf = NumberFormat.getCurrencyInstance(locs[22]);

        txtSoDuToiThieu.setText(nf.format(soDuToiThieu));
        txtGuiToiThieu.setText(nf.format(guiToiThieu));
        txtRutToiThieuGD.setText(nf.format(rutToiThieuGD));
        txtRutToiDaGD.setText(nf.format(rutToiDaGD));
        txtRutToiDaN.setText(nf.format(rutToiDaN));
        txtSoLanRutToiDaN.setText(String.valueOf(soLanRutToiDaN));

        txtSoDuToiThieu.setEditable(false);
        txtGuiToiThieu.setEditable(false);
        txtRutToiThieuGD.setEditable(false);
        txtRutToiDaGD.setEditable(false);
        txtRutToiDaN.setEditable(false);
        txtSoLanRutToiDaN.setEditable(false);
        btnSua.setEnabled(true);
        btnLuu.setEnabled(false);
        new CustomMessageDialog(null, true, "Done!", "Sửa thành công!", CustomMessageDialog.DONE);
    }//GEN-LAST:event_btnLuuActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnLuu;
    private javax.swing.JButton btnSua;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToggleButton jToggleButton1;
    private org.jdesktop.swingx.JXTextArea jXTextArea1;
    private org.jdesktop.swingx.JXTextArea jXTextArea2;
    private org.jdesktop.swingx.JXTextArea jXTextArea3;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator1;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator2;
    private org.jdesktop.swingx.JXTitledSeparator jXTitledSeparator3;
    private javax.swing.JTextField txtGuiToiThieu;
    private javax.swing.JTextField txtRutToiDaGD;
    private javax.swing.JTextField txtRutToiDaN;
    private javax.swing.JTextField txtRutToiThieuGD;
    private javax.swing.JTextField txtSoDuToiThieu;
    private javax.swing.JTextField txtSoLanRutToiDaN;
    // End of variables declaration//GEN-END:variables
}